package com.card.message;

import com.card.common.MessageComm;
import com.card.game.BasePlayer;
import com.card.user.User;
import com.card.user.UserBase;
import com.card.user.UserManager;
import com.xiaoao.net.json.message.JsonMessage;

/**
 * 消息处理中心，负责消息的发送
 * @Author: siyunlong
 * @Version: V1.00
 * @Create Date: 2015-5-8下午3:24:16
 */
public class JsonMessageCenter extends com.xiaoao.net.json.message.JsonMessageCenter{

    private static final JsonMessageCenter instance = new JsonMessageCenter();

    public static JsonMessageCenter getInstance() {
        return instance;
    }
    
    public void sendMessage(JsonMessage message,BasePlayer player) {
    	User user = UserManager.getInstance().getUserByKey(player.getUserId());
		if(user != null) {
			sendMessage(message, user);
		}
    }
    public void sendMessage(JsonMessage message,String userId) {
    	User user = UserManager.getInstance().getUserByKey(userId);
		if(user != null) {
			sendMessage(message, user);
		}
    }
    
    public void sendMessage(JsonMessage message,UserBase user) {
//		sendMessage(message, user.getCtx());
    	user.addMessage2Queue(message);
    }	
    
    public void sendEorrorMessage(User user,String errorMsg) {
    	JsonMessage message = new JsonMessage(MessageComm.S2C_ErrorMsg);
    	message.addProperty("msg", errorMsg);
    	sendMessage(message, user);
    }	
}
